import { apiService, cancelToken, sourceToken } from "@/utils/rtkQuery";

export const counterApi = apiService
  .enhanceEndpoints({
    addTagTypes: [],
  })
  .injectEndpoints({
    endpoints: ({ query, mutation }) => ({
      getCounter: query({
        //query: () => '/api/counters',
        query: () => ({
          url: "/api/counters",
          cancelToken: sourceToken,
        }),
      }),
      getList: query({
        query: () => ({
          url: "/api/list",
          cancelToken: sourceToken,
        }),
      }),
      setCounter: mutation({
        query: (data) => ({
          url: "/api/counter/set",
          method: "POST",
          data: data,
          cancelToken: sourceToken,
        }),
      }),
    }),
  });

export const { useGetCounterQuery, useGetListQuery, useSetCounterMutation } = counterApi;
export { cancelToken };
export default counterApi;
